package net.huashitong.Indicators.web;

import com.alibaba.fastjson.JSONObject;
import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.utils.NumberUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import freemarker.template.Template;
import net.huashitong.Indicators.DTO.*;
import net.huashitong.Indicators.DTO.guTou.GuTouXZDTO;
import net.huashitong.Indicators.DTO.guTou.GutouZdDTO;
import net.huashitong.Indicators.DTO.sheLing.SheLingDTO;
import net.huashitong.Indicators.DTO.sheLing.SheLingPctDTO;
import net.huashitong.Indicators.entity.CompletionClassification;
import net.huashitong.Indicators.entity.IndicatorBreakdown;
import net.huashitong.Indicators.filter.IndicatorBreakdownFilter;
import net.huashitong.Indicators.filter.IndicatorRank;
import net.huashitong.Indicators.service.CompletionClassificationService;
import net.huashitong.Indicators.service.IndicatorBreakdownService;
import net.huashitong.scheduling.entity.FinanceIncome;
import net.huashitong.scheduling.service.FinanceIncomeService;
import net.huashitong.threeSeven.entity.IndexData;
import net.huashitong.threeSeven.entity.JdFinishDetail;
import net.huashitong.threeSeven.filter.IndexDataFilter;
import net.huashitong.threeSeven.filter.RequestModelFilter;
import net.huashitong.threeSeven.service.IndexDataService;
import net.huashitong.threeSeven.service.JdFinishDeatilService;
import net.huashitong.user.utils.UtilsTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.Table;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;

import static net.huashitong.Indicators.utils.DataUtils.formaterDecimal;
import static net.huashitong.user.utils.UtilsTools.formatWan;
import static net.huashitong.user.utils.UtilsTools.keepNumPostion;

/**
 * 数字冰雹二期接口
 */
@Controller
@RequestMapping("/api/ecoSec/")
public class ShuZiBingBaoCtrl extends JsonBaseController {


    @Autowired
    private IndicatorBreakdownService indicatorService;

    @Autowired
    private IndexDataService indexDataService;

    @Autowired
    private CompletionClassificationService clssificaService;

    @Autowired
    private FinanceIncomeService financeIncomeService;

    @Autowired
    private JdFinishDeatilService jdFinishDeatilService;


    @Override
    protected String getView(String s) {
        return null;
    }


    //GDP
    @ResponseBody
    @RequestMapping(value = "/queryGDP", method = RequestMethod.GET)
    public Map<String, Object> queryGDP() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A01");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> a01 = indicatorService.getRank3("A01", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        for (IndicatorRank rank : a01) {
            //BBRankDTO dto  = new BBRankDTO();
            //int ranks = StringUtils.isBlank(rank.getRank())?"0":Integer.parseInt(rank.getRank());
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }

        map.put("GDPRank", rankDtos);
        List<String> ids = new ArrayList<>();
        ids.add(0, "A02");
        ids.add(1, "A03");
        ids.add(2, "A06");
        List<PctDTO> ptcData = getPTCData(ids, "永泰县", currentDate);
        map.put("GDPPCT", ptcData);
        return map;
    }


    //一产 A02
    //二产 A03
    //三产 A06
    @ResponseBody
    @RequestMapping(value = "/queryYiChan", method = RequestMethod.GET)
    public Map<String, Object> queryYiChan() {

        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A02");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> a02 = indicatorService.getRank3("A02", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        for (IndicatorRank rank : a02) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("InduOneRank", rankDtos);
        return map;
    }


    //计算成分百分比
    public List<PctDTO> getPTCData(List<String> indistryIds, String area, String datetime) {

        IndicatorBreakdown breakdown = new IndicatorBreakdown();
        breakdown.setCurrentMonth(datetime);
        breakdown.setIndustryId(indistryIds.get(0));
        breakdown.setArea(area);
        List<PctDTO> pctlist = new ArrayList<>();
        double total = 0.0;
        double sum = 0.0;
        for (int i = 0; i < indistryIds.size(); i++) {

            breakdown.setIndustryId(indistryIds.get(i));
            IndicatorBreakdown indData = indicatorService.queryByDateAndId(breakdown);

            if (ObjectUtils.isNotBlank(indData)) {
                sum = StringUtils.isBlank(indData.getCumulative()) ? 0.0 :
                        keepNumPostion(1, Double.parseDouble(indData.getCumulative())) + sum;
                pctlist.add(new PctDTO(indData.getIndustryName(),
                        keepNumPostion(1, Double.parseDouble(indData.getCumulative())), UtilsTools.formatDate(datetime)));
            }
            if (i == (indistryIds.size() - 1)) {
                for (PctDTO dto : pctlist) {
                    dto.setPct(keepNumPostion(1, (dto.getPct() / sum) * 100));
                }
            }
        }
        return pctlist;
    }

    // 二产接口
    @ResponseBody
    @RequestMapping(value = "/queryErChan", method = RequestMethod.GET)
    public Map<String, Object> queryErChan() {
        //A05  规模以上工业增加值   A04 工业增加值
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A03");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> A03 = indicatorService.getRank3("A03", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        for (IndicatorRank rank : A03) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }

        map.put("InduTwoRank", rankDtos);
        //A05  规模以上工业增加值   A04
        List<String> ids = new ArrayList<>();
        ids.add(0, "A20");
        ids.add(1, "A08");
        //（工业增加值、建筑业增加值构成）
        List<PctDTO> ptcData = getPTCData(ids, "永泰县", currentDate);
        map.put("econ_zs_ind_pct", ptcData);

        IndicatorBreakdown breakdown = new IndicatorBreakdown();
        breakdown.setIndustryId("A20");
        breakdown.setArea("永泰县");
        breakdown.setCurrentMonth(currentDate);

        List<HashMap<String, Object>> mapList = new ArrayList<>();
        IndicatorBreakdown indData = indicatorService.queryByDateAndId(breakdown);
        if (ObjectUtils.isNotBlank(indData)) {
            HashMap<String, Object> A05 = new HashMap<>();
            A05.put("typeName", indData.getIndustryName());
            A05.put("growthRate", indData.getRatio());
            A05.put("industry", StringUtils.isBlank(indData.getCumulative()) ? 0.0 : (
                    keepNumPostion(1, Double.parseDouble(indData.getCumulative()))));
            A05.put("time", UtilsTools.formatDate(indData.getCurrentMonth()));
            mapList.add(A05);
        }


        breakdown.setIndustryId("A08");
        indData = indicatorService.queryByDateAndId(breakdown);
        if (ObjectUtils.isNotBlank(indData)) {
            HashMap<String, Object> A06 = new HashMap<>();
            A06.put("typeName", indData.getIndustryName());
            A06.put("growthRate", indData.getRatio());
            A06.put("industry", StringUtils.isBlank(indData.getCumulative()) ? 0.0 : (
                    keepNumPostion(1, Double.parseDouble(indData.getCumulative()))));
            A06.put("time", UtilsTools.formatDate(indData.getCurrentMonth()));
            mapList.add(A06);
        }

        map.put("econ_zs_industry_construction_growth", mapList);
        return map;
    }

    // 三产
    @ResponseBody
    @RequestMapping("/querySanChan")
    public Map<String, Object> querySanChan() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A06");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> A06 = indicatorService.getRank3("A06", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : A06) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("InduThreeRank", rankDtos);

        String[] industryId = {"A002", "A003", "A004", "A005", "A006", "A007", "A008"};
        Map<String, Object> m = indexDataService.getNewDateTime(new IndexDataFilter());
        IndexDataFilter filter = new IndexDataFilter();
        currentDate = (String) m.get("dateTime");
        filter.setDateTime(currentDate);
        double sum = 0.0;
        RequestModelFilter requestModelFilter = new RequestModelFilter();
        requestModelFilter.setDateTime(currentDate);
        List<JdFinishDetail> list = jdFinishDeatilService.queryByTime(requestModelFilter);

        for (int i = 0; i < industryId.length; i++) {

            for (JdFinishDetail detail : list) {
                if (industryId[i].equals(detail.getIndexCode())) {
                    HashMap<String, Object> indexMap = new HashMap<>();

                    String indexName = detail.getIndexName();
                    String resultIndexName = "";
                    switch (indexName) {
                        case "批发和零售业":
                            resultIndexName = "批发和零售";
                            break;
                        case "交通运输、仓储和邮政业":
                            resultIndexName = "交通仓储和邮政";
                            break;
                        case "住宿和餐饮业":
                            resultIndexName = "住宿和餐饮";
                            break;
                        case "金融业":
                            resultIndexName = "金融";
                            break;
                        case "房地产业":
                            resultIndexName = "房地产";
                            break;
                        case "营利性服务业":
                            resultIndexName = "盈利性服务";
                            break;
                        case "非营利性服务业":
                            resultIndexName = "非营利性服务";
                            break;
                        default:
                            resultIndexName = indexName;
                    }
                    indexMap.put("typeName", resultIndexName);
                    indexMap.put("growthRate", StringUtils.isBlank(detail.getIncrease()) ? 0 : Double.parseDouble(detail.getIncrease()));
                    indexMap.put("total", StringUtils.isBlank(detail.getTotal()) ? 0.0 : (
                            keepNumPostion(1, Double.parseDouble(detail.getTotal()))));
                    indexMap.put("time", StringUtils.isBlank(detail.getJdTime()) ? "2019-09-01 00:00:00" : UtilsTools.formatDate(detail.getJdTime()));
                    sum = (StringUtils.isBlank(detail.getTotal()) ? 0 : (
                            keepNumPostion(1, Double.parseDouble(detail.getTotal())))) + sum;
                    mapList.add(indexMap);
                    continue;
                }
            }
        }
        for (HashMap<String, Object> itemMap : mapList) {
            if (sum == 0) {
                itemMap.put("pct", 0);
            } else {
                double total = (double) itemMap.get("total");
                itemMap.put("pct", new BigDecimal((total / sum) * 100).setScale(0, BigDecimal.ROUND_HALF_UP));
            }
        }

        map.put("econ_zs_threeind_info", mapList);
        return map;
    }

    //农业产值
    @ResponseBody
    @RequestMapping("/queryAgro")
    public Map<String, Object> queryAgro() {

        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A11");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A11", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.00 :
                    keepNumPostion(2, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("AgroRank", rankDtos);

        IndicatorBreakdownFilter fi = new IndicatorBreakdownFilter();
        fi.setArea("永泰县");
        fi.setIndustryId("A02");
        fi.setDate("201901-12");
        fi.setHy("行业");

        List<CompletionClassification> list = clssificaService.queryByHYValueSec(fi);

        List<HashMap<String, Object>> listmap = new ArrayList<>();
        Double total = 0.0;
        for (CompletionClassification item : list) {
            if ("农林牧渔业".equals(item.getCategoryDetails())) {
                total = Double.parseDouble(item.getActualCompletionValue());
            }
        }
        for (CompletionClassification item : list) {
            HashMap<String, Object> itemMap = new HashMap<>();
            switch (item.getCategoryDetails()) {
                case "农林牧渔服务":
                    itemMap.put("name", "农林牧渔服务业产值");
                    break;
                case "农业":
                    itemMap.put("name", "农业产值");
                    break;
                case "林业":
                    itemMap.put("name", "林业产值");
                    break;
                case "牧业":
                    itemMap.put("name", "牧业产值");
                    break;
                case "渔业":
                    itemMap.put("name", "渔业产值");
                    break;
                case "农林牧渔业":
                    itemMap.put("name", "农林牧渔业总产值");
                    break;
                default:
                    break;
            }
            itemMap.put("total", StringUtils.isBlank(item.getActualCompletionValue()) ? 0 : (
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue()));
            itemMap.put("pct", StringUtils.isBlank(item.getActualCompletionValue()) ? "0" :
                    NumberUtils.doubleFormat(StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                            Double.parseDouble(item.getActualCompletionValue())
                                    / total * 100, 1));
            itemMap.put("time", UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", "")));
            listmap.add(itemMap);
        }

        map.put("econ_zx_agro_info", listmap);

        return map;
    }


    //规模以上工业总产值
    @ResponseBody
    @RequestMapping(value = "/queryBigIndustry", method = RequestMethod.GET)
    public Map<String, Object> queryBigIndustry() {

        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A05");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A05", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("Economy_Industryincreaseranktwo", rankDtos);

        //规模以上工业 企业完成
        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setXz(null);
        filter.setHy(null);
        filter.setQy("企业");
        //获取最新时间
        String newDate1 = clssificaService.queryNewDate(filter);
        filter.setDate(newDate1);

        filter.setArea("永泰县");
        filter.setIndustryId("A05");
       /* int leng = currentDate.length();
        String month = currentDate.substring(leng - 2, leng - 1);
        String year = currentDate.substring(0,4);
        String newDate = year+"01-"+month;*/

        List<CompletionClassification> list = clssificaService.queryByDWValue(filter);
        System.out.println(list);
        List<GongYeDTO> gongyeList = new ArrayList<>();
        for (CompletionClassification item : list) {
            double leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getActualCompletionValue()));
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            gongyeList.add(new GongYeDTO(item.getCategoryDetails(), leiji, rate, datetime));

        }
        System.out.println(gongyeList);
        map.put("ECON_ZX_BigIndustry_Ent", gongyeList);

        //分乡镇产值 增速 econ_zx_bigindustry_town


        filter.setHy(null);
        filter.setQy(null);
        filter.setXz("乡镇");
        //获取最新时间
        String newDate2 = clssificaService.queryNewDate(filter);
        filter.setDate(newDate2);

        List<CompletionClassification> xiangzhenList = clssificaService.queryByXZValue(filter);
        List<GongyeXZDTO> towmlist = new ArrayList<>();
        for (CompletionClassification item : xiangzhenList) {
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            int cum = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            double comp = StringUtils.isBlank(item.getCompleteAnnual()) ? 0 : Double.parseDouble(item.getCompleteAnnual());
            String time = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            towmlist.add(new GongyeXZDTO(item.getCategoryDetails(), target, cum, rate, comp, time));
        }
        map.put("econ_zx_bigindustry_town", towmlist);

        // 行业产值
        filter.setXz(null);
        filter.setQy(null);
        filter.setHy("行业");
        //获取最新时间
        String newDate3 = clssificaService.queryNewDate(filter);
        filter.setDate(newDate3);

        CompletionClassification hyList1 = clssificaService.queryByHYValue1OrderBycompletionPeriod(filter);
        String date = hyList1.getCompletionPeriod();
        filter.setDate(date);
        List<CompletionClassification> hyList = clssificaService.queryByHYValue1(filter);
        List<GongYeDTO> hangyeList = new ArrayList<>();
        for (CompletionClassification item : hyList) {
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            double leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getActualCompletionValue()));
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));

            hangyeList.add(new GongYeDTO(item.getCategoryDetails(), leiji, rate, datetime));
        }
        map.put("ECON_ZX_BigIndustry_Trade", hangyeList);
        return map;
    }


    //固投
    @ResponseBody
    @RequestMapping(value = "/queryIIFA", method = RequestMethod.GET)
    public Map<String, Object> queryIIFA() {
        // IIFARank
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A07");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A07", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("IIFARank", rankDtos);
        // ECON_ZX_IIFA_Project 全部重点投资项目完成情况

        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A07");
       /* int leng = currentDate.length();
        String month = currentDate.substring(leng - 2, leng - 1);
        String year = currentDate.substring(0,4);
        String newDate = year+"01-"+month;*/
        filter.setBm("项目");

        //获取最新时间
        String newDate3 = clssificaService.queryNewDateGuTou(filter);
        filter.setDate(newDate3);


        List<CompletionClassification> xiangmuList = clssificaService.queryByValue(filter);
        List<GutouZdDTO> xmList = new ArrayList<>();
        for (CompletionClassification item : xiangmuList) {
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            xmList.add(new GutouZdDTO(item.getCategoryDetails(), target, leiji, rate, datetime));
        }
        map.put("ECON_ZX_IIFA_Project", xmList);

        //	ECON_ZX_IIFA_Dept 部门
        filter.setBm("部门");
        List<CompletionClassification> bumenList = clssificaService.queryByValue(filter);
        List<GutouZdDTO> bmList = new ArrayList<>();
        for (CompletionClassification item : bumenList) {
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            bmList.add(new GutouZdDTO(item.getCategoryDetails(), target, leiji, rate, datetime));

        }
        map.put("ECON_ZX_IIFA_Dept", bmList);


        //3.3.2.4.	ECON_ZX_BigIndustry_Trade  50万元以上
        filter.setBm("乡镇");
        List<CompletionClassification> xzdataList = clssificaService.queryByValue(filter);
        List<GuTouXZDTO> zxlist = new ArrayList<>();
        for (CompletionClassification item : xzdataList) {
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();

            double comp = StringUtils.isBlank(item.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getCumulative()));

            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            zxlist.add(new GuTouXZDTO(item.getCategoryDetails(), target, leiji, rate, comp, datetime));

        }


        map.put("ECON_ZX_BigIndustry_Trade", zxlist);
        return map;
    }


    //社会消费品零售
    @ResponseBody
    @RequestMapping(value = "/queryRetail", method = RequestMethod.GET)
    public Map<String, Object> queryRetail() {
        // IIFARank
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A13");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A13", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("RetailRank", rankDtos);

        // econ_zx_retail_ent  全部限额以上企业完成量
        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A13");
        filter.setBm("商贸业");
        //获取最新时间
        String newDate3 = clssificaService.queryNewDateGuTou(filter);
        filter.setDate(newDate3);

        List<CompletionClassification> qiyeList = clssificaService.queryByValue(filter);
        List<SheLingPctDTO> listQY = new ArrayList<>();
        for (CompletionClassification item : qiyeList) {

            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));

            listQY.add(new SheLingPctDTO(item.getCategoryDetails(), rate, datetime, leiji));

        }
        map.put("econ_zx_retail_ent", listQY);

        //econ_zx_retail_town  分乡镇收入
        filter.setDate("201901-09");
        filter.setBm("乡镇");
        List<CompletionClassification> xiangzhen = clssificaService.queryByValue(filter);
        List<SheLingDTO> xzList = new ArrayList<>();
        for (CompletionClassification item : xiangzhen) {

            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getCumulative()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getCumulative())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            double cum = StringUtils.isBlank(item.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getCumulative()));

            xzList.add(new SheLingDTO(item.getCategoryDetails(), target, leiji, rate, cum, datetime));

        }
        map.put("econ_zx_retail_town", xzList);
        return map;
    }

    //建筑业
    @ResponseBody
    @RequestMapping(value = "/queryConst", method = RequestMethod.GET)
    public Map<String, Object> queryConst() {
        // IIFARank
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A04");
        String currentDate = indicator.getCurrentMonth();

        //3.5.2.1.	econ_ys_const_ent

        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A04");
        filter.setBm("企业");
        //获取最新时间
        String newDate3 = clssificaService.queryNewDateGuTou(filter);
        filter.setDate(newDate3);
        List<CompletionClassification> qiyeList = clssificaService.queryByValue(filter);
        List<GongyeXZDTO> listQY = new ArrayList<>();
        String datetime = "";
        for (CompletionClassification item : qiyeList) {

            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();

            double comp = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getActualCompletionValue()));

            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));

            listQY.add(new GongyeXZDTO(item.getCategoryDetails(), target, leiji, rate, comp, datetime));

        }
        map.put("econ_ys_const_ent", listQY);

        //	econ_ys_const_info  市内市外 构成（无数据，模拟数据）
        List<Map<String, Object>> modelList = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("Name", "建筑业总产值");
        map1.put("Total", 8235212);
        map1.put("PCT", 100.0);
        map1.put("Time", "2020-09-01 00:00:00");
        modelList.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("Name", "市内建筑业产值");
        map2.put("Total", 1661054);
        map2.put("PCT", 22.67);
        map2.put("Time", "2020-09-01 00:00:00");
        modelList.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("Name", "市外省内建筑业产值");
        map3.put("Total", 0);
        map3.put("PCT", 0);
        map3.put("Time", "2020-09-01 00:00:00");
        modelList.add(map3);
        Map<String, Object> map4 = new HashMap<>();
        map4.put("Name", "省外建筑业产值");
        map4.put("Total", 5665552);
        map4.put("PCT", 77.33);
        map4.put("Time", "2020-09-01 00:00:00");
        modelList.add(map4);
        map.put("econ_ys_const_info", modelList);
        return map;
    }

    //工业固投
    @ResponseBody
    @RequestMapping(value = "/queryIndustryIIFA", method = RequestMethod.GET)
    public Map<String, Object> queryIndustryIIFA() {
        // IIFARank
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A08");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A08", currentDate);

        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            //BBRankDTO dto  = new BBRankDTO();
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("IndustryIIFARank", rankDtos);


        //Econ_YS_industryIIFA_project(模拟数据)
        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A07");
        filter.setBm("项目");
        //获取最新时间
        String newDate3 = clssificaService.queryNewDateGuTou(filter);
        filter.setDate(newDate3);
        filter.setPosition("工业固投");
        List<CompletionClassification> xiangmuList = clssificaService.queryByValue(filter);
        List<GutouZdDTO> xmList = new ArrayList<>();
        for (CompletionClassification item : xiangmuList) {
            int target = StringUtils.isBlank(item.getPlanneValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue())).intValue();
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            int leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue())).intValue();
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            xmList.add(new GutouZdDTO(item.getCategoryDetails(), target, leiji, rate, datetime));
        }
        map.put("Econ_YS_industryIIFA_project", xmList);
//        map.put("Econ_YS_industryIIFA_project", new ArrayList<GongyeXZDTO>());
        return map;
    }


    /**
     * 财政总收入
     * queryReceipts
     */
    @ResponseBody
    @RequestMapping(value = "/queryReceipts", method = RequestMethod.GET)
    public Map<String, Object> queryReceipts() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A09");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A09", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("IndustryIIFARank", rankDtos);
        //3.7.2.2.	Econ_YS_Gov_receipts_Level  地方收入与中央收入构成
        List<FinanceIncome> financeIncomes = financeIncomeService.queryByDate();
        String dataTime = financeIncomeService.queryNewDate();
        double total = 0.0;
        for (FinanceIncome financeIncome : financeIncomes) {
            if (financeIncome.getName().contains("中央一般公共预算收入") || financeIncome.getName().contains("地方公共财政收入合计")) {
                total = total + Double.parseDouble(financeIncome.getCurrentMonthIncome());
            }
        }

        List<Map<String, Object>> res = new ArrayList<>();
        for (FinanceIncome financeIncome : financeIncomes) {
            if (financeIncome.getName().contains("中央一般公共预算收入")) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("TypeName", "中央");
                map1.put("PCT", keepNumPostion(2, Double.parseDouble(financeIncome.getCurrentMonthIncome()) / total * 100));
                map1.put("Total", Integer.parseInt(financeIncome.getCurrentMonthIncome()));
                map1.put("Time", UtilsTools.formatDate(dataTime.substring(0, 4)
                        + dataTime.substring(5, 7)));
                res.add(map1);
            }
            if (financeIncome.getName().contains("地方公共财政收入合计")) {
                Map<String, Object> map2 = new HashMap<>();
                map2.put("TypeName", "地方级");
                map2.put("PCT", keepNumPostion(2, Double.parseDouble(financeIncome.getCurrentMonthIncome()) / total * 100));

                map2.put("Total", Integer.parseInt(financeIncome.getCurrentMonthIncome()));
                map2.put("Time", UtilsTools.formatDate(dataTime.substring(0, 4)
                        + dataTime.substring(5, 7)));
                res.add(map2);
            }
        }
        map.put("Econ_YS_Gov_receipts_Level", res);


        //分部门收入（模拟数据）
        List<Map<String, Object>> modelList = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("Name", "财政部门");
        map1.put("Total", 20152);
        map1.put("PCT", 100.0);
        map1.put("Time", UtilsTools.formatDate(dataTime.substring(0, 4)
                + dataTime.substring(5, 7)));
        modelList.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("Name", "地税部门");
        map2.put("Total", 152642);
        map2.put("PCT", 32.4);
        map2.put("Time", UtilsTools.formatDate(dataTime.substring(0, 4)
                + dataTime.substring(5, 7)));
        modelList.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("Name", "国税部门");
        map3.put("Total", 169152);
        map3.put("PCT", 19.1);
        map3.put("Time", UtilsTools.formatDate(dataTime.substring(0, 4)
                + dataTime.substring(5, 7)));
        modelList.add(map3);
        map.put("Econ_YS_Gov_receipts_Info", modelList);
        return map;
    }

    /**
     * 一般公共预算收入
     * queryReceipts
     */
    @ResponseBody
    @RequestMapping(value = "/queryReceipts2", method = RequestMethod.GET)
    public Map<String, Object> queryReceipts2() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A10");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A10", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("BudgetRank", rankDtos);
        //Econ_YS_budget_receipts_Info   分税种收入

        List<FinanceIncome> incomes = financeIncomeService.queryListByParentId("1185");
        List<GongyeXZDTO> incomesList = new ArrayList<>();

        for (FinanceIncome item : incomes) {

            int target = StringUtils.isBlank(item.getBegingBudget()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getBegingBudget())).intValue();
            String datetime = item.getYear() + item.getMonth();
            int total = StringUtils.isBlank(item.getCurrentYearIncome()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(item.getCurrentYearIncome())).intValue();

            double comp = StringUtils.isBlank(item.getCurrentMonthIncome()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getCurrentMonthIncome()));

            double rate = StringUtils.isBlank(item.getIncreDecre()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getIncreDecre()));

            incomesList.add(new GongyeXZDTO(item.getName(), target, total, rate, comp, UtilsTools.formatDate(datetime)));
        }
        map.put("Econ_YS_budget_receipts_Info", incomesList);

        return map;
    }


    /**
     * 出口值  A14
     */
    @ResponseBody
    @RequestMapping(value = "/queryBudget", method = RequestMethod.GET)
    public Map<String, Object> queryBudget() throws ParseException {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A14");
        String currentDate = "";

        if ("0".equals(indicator.getCumulative()) && "0".equals(indicator.getRatio())) {
            //当月为0，则取上一个月的值
            currentDate = financeIncomeService.getSecondMonth(indicator.getCurrentMonth());
        } else {
            currentDate = indicator.getCurrentMonth();
        }

        List<IndicatorRank> data = indicatorService.getRank3("A14", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()) / 10000);
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }


        //econ_YX_Export_Ent

        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A14");
//        filter.setDate("201801-08");
        filter.setBm("企业");

        //获取最新时间
        String newDate3 = clssificaService.queryNewDateGuTou(filter);
        filter.setDate(newDate3);

        List<CompletionClassification> qiyeList = clssificaService.queryByValue(filter);
        List<GongYeDTO> listQY = new ArrayList<>();

        //规模数据最新时间
        IndicatorBreakdownFilter filter1 = new IndicatorBreakdownFilter();
        filter1.setXz(null);
        filter1.setHy(null);
        filter1.setQy("企业");
        //获取最新时间
        String newDate1 = clssificaService.queryNewDate(filter1);
        String datetimeDemo = UtilsTools.formatDate(newDate1.replace("01-", ""));
        for (CompletionClassification item : qiyeList) {

            // double target = StringUtils.isBlank(item.getPlanneValue())?0:Double.parseDouble(item.getPlanneValue());
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            // double comp = StringUtils.isBlank(item.getActualCompletionValue())?0:Double.parseDouble(item.getActualCompletionValue());
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            double leiji = StringUtils.isBlank(item.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getCumulative()));
            //这部分数据没有最新的，模拟数据，改成最新时间
            listQY.add(new GongYeDTO(item.getCategoryDetails(), leiji, rate, datetimeDemo));

        }
        map.put("econ_YX_Export_Ent", listQY);

        //3.9.2.3.	Econ_YX_Exprot_Town 出口 分乡镇

        List<BBRankDTO> chukouXZ = new ArrayList<>();
        filter.setBm("乡镇");
        filter.setDate("201801-08");
        List<CompletionClassification> xzList = clssificaService.queryByValue(filter);
        for (CompletionClassification item : xzList) {
            double target = StringUtils.isBlank(item.getPlanneValue()) ? 0.0 :
                    keepNumPostion(0, Double.parseDouble(item.getPlanneValue()));
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            double comp = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getActualCompletionValue()));
            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            double leiji = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(0, Double.parseDouble(item.getActualCompletionValue()) / 10000);

            chukouXZ.add(new BBRankDTO(item.getCategoryDetails(), 0, rate, leiji, datetime));
        }
        //排序
        Collections.sort(chukouXZ, new Comparator<BBRankDTO>() {
            @Override
            public int compare(BBRankDTO o1, BBRankDTO o2) {
                return -Double.compare(o1.getProductValue(), o2.getProductValue());
            }
        });
        //设置排名
        for (int i = 0; i < chukouXZ.size(); i++) {
            chukouXZ.get(i).setRanking(i + 1);
        }
        map.put("Econ_YX_Exprot_Town", chukouXZ);

        if (rankDtos.size() == 0) {
            map.put("ExportRank", chukouXZ);
        } else {
            map.put("ExportRank", rankDtos);
        }
        return map;
    }

    /**
     * 外资 A15
     */
    @ResponseBody
    @RequestMapping(value = "/queryFireign", method = RequestMethod.GET)
    public Map<String, Object> queryFireign() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A15");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A15", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            if ("福州市".equals(rank.getArea())) {
                continue;
            }
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            int total = StringUtils.isBlank(rank.getCumulative()) ? 0 :
                    keepNumPostion(0, Double.parseDouble(rank.getCumulative())).intValue();
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()));
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime, total));
        }
        map.put("ExportRank", rankDtos);
        //3.10.2.2.	Econ_YX_Foreign_capital_Ent  所有企业完成情况
        IndicatorBreakdownFilter filter = new IndicatorBreakdownFilter();
        filter.setArea("永泰县");
        filter.setIndustryId("A15");
        filter.setDate("201801-08");
        filter.setBm("企业");
        List<CompletionClassification> qiyeList = clssificaService.queryByValue(filter);
        List<GongYeDTO> listQY = new ArrayList<>();
        for (CompletionClassification item : qiyeList) {
            double target = StringUtils.isBlank(item.getPlanneValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getPlanneValue()));
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            double leiji = StringUtils.isBlank(item.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getCumulative()));

            double comp = StringUtils.isBlank(item.getActualCompletionValue()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getActualCompletionValue()));

            double rate = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            listQY.add(new GongYeDTO(item.getCategoryDetails(), leiji, rate, datetime));

        }
        map.put("Econ_YX_Foreign_capital_Ent", listQY);
        //实际利用外资分乡镇
        List<WaiziDTO> xzwaizilist = new ArrayList<>();
        filter.setBm("乡镇");
        List<CompletionClassification> xzList = clssificaService.queryByValue(filter);
        for (CompletionClassification item : xzList) {

            double rattio = StringUtils.isBlank(item.getSpecificIncrease()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(item.getSpecificIncrease()));
            String datetime = UtilsTools.formatDate(item.getCompletionPeriod().replace("01-", ""));
            if (rattio == 0.0) {
                continue;
            }
            xzwaizilist.add(new WaiziDTO(item.getCategoryDetails(), rattio, datetime));
        }
        map.put("Econ_YX_Exprot_Town", xzwaizilist);
        return map;
    }


    /**
     * 居民收入  A18
     */
    @ResponseBody
    @RequestMapping(value = "/queryIncome", method = RequestMethod.GET)
    public Map<String, Object> queryIncome() {
        HashMap<String, Object> map = new HashMap<>();
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A18");
        String currentDate = indicator.getCurrentMonth();
        List<IndicatorRank> data = indicatorService.getRank3("A18", currentDate);
        List<BBRankDTO> rankDtos = new ArrayList<>();
        List<HashMap<String, Object>> mapList = new ArrayList<>();
        for (IndicatorRank rank : data) {
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(2, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(2, Double.parseDouble(rank.getCumulative()));
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("CityIncomeRank", rankDtos);

        data = indicatorService.getRank3("A19", currentDate);
        List<BBRankDTO> rankDtos2 = new ArrayList<>();
        for (IndicatorRank rank : data) {
            double ratio = StringUtils.isBlank(rank.getRatio()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getRatio()));
            double cum = StringUtils.isBlank(rank.getCumulative()) ? 0.0 :
                    keepNumPostion(1, Double.parseDouble(rank.getCumulative()));
            String datime = UtilsTools.formatDate(rank.getCurrentMonth());
            rankDtos2.add(new BBRankDTO(rank.getArea(), rank.getRank().intValue(), ratio, cum, datime));
        }
        map.put("VillageIncomeRank", rankDtos2);
        return map;
    }

    //永泰综合经济
    @ResponseBody
    @RequestMapping(value = "/queryCompEcon", method = RequestMethod.GET)
    public List<CompEconDto> queryCompEcon() throws ParseException {
        TreeMap<Integer, String> codeMap = new TreeMap() {
            {
                put(1, "A01"); //GDP
                put(2, "A02"); //一产
                put(3, "A03");//二产
                put(4, "A06");//三产
                put(5, "A11");//农业
                put(6, "A05");//工业
                put(7, "A07");//固投
                put(8, "A13");//社零
                put(9, "A04");//建筑业
                put(10, "A08");//工业固投
                put(11, "A09");//财政总收入
                put(12, "A10");//一般预算收入
                put(13, "A14");//进出口总值
                put(14, "A15");//实际利用外资
                put(15, "A18");//城镇收入
                put(16, "A19");//农村收入
            }
        };

        Set<Integer> keyset = codeMap.keySet();
        Iterator<Integer> iterator = keyset.iterator();
        List<CompEconDto> ecolist = new ArrayList<>();

        while (iterator.hasNext()) {
            Integer key = iterator.next();
            String unit = "";
            String typeName = "";
            switch (key) {
                case 1:
                    typeName = "地区生产总值";
                    unit = "亿元";
                    break;
                case 2:
                    typeName = "第一产业增加值";
                    unit = "亿元";
                    break;
                case 3:
                    typeName = "第二产业增加值";
                    unit = "亿元";
                    break;
                case 4:
                    typeName = "第三产业增加值";
                    unit = "亿元";
                    break;
                case 5:
                    typeName = "农林牧渔业总产值";
                    unit = "亿元";
                    break;
                case 6:
                    typeName = "规模以上工业增加值";
                    unit = "亿元";
                    break;
                case 7:
                    typeName = "固定资产投资";
                    unit = "亿元";
                    break;
                case 8:
                    typeName = "社会消费品零售总额";
                    unit = "亿元";
                    break;
                case 9:
                    typeName = "建筑业增加值";
                    unit = "万元";
                    break;
                case 10:
                    typeName = "工业固投";
                    unit = "亿元";
                    break;
                case 11:
                    typeName = "一般公共预算总收入";
                    unit = "万元";
                    break;
                case 12:
                    typeName = "一般公共预算收入";
                    unit = "亿元";
                    break;
                case 13:
                    typeName = "进出口总值";
                    unit = "亿元";
                    break;
                case 14:
                    typeName = "实际利用外资";
                    unit = "亿元";
                    break;
                case 15:
                    typeName = "城镇居民人均可支配收入";
                    unit = "元";
                    break;
                case 16:
                    typeName = "农村居民人均可支配收入";
                    unit = "元";
                    break;
                default:
                    break;
            }

            String code = codeMap.get(key);
            IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime(code);

            String currentMonth = indicator.getCurrentMonth();

            if ("A14".equals(code)) {
                if ("0".equals(indicator.getCumulative()) && "0".equals(indicator.getRatio())) {
                    //当月为0，则取上一个月的值
                    currentMonth = financeIncomeService.getSecondMonth(indicator.getCurrentMonth());
                } else {
                    currentMonth = indicator.getCurrentMonth();
                }
            }
            //固定资产投资取最新数据
            if ("A07".equals(code)) {
                List<IndicatorBreakdown> list = indicatorService.queryIndicatorBreakdowns("永泰县", "A07", null);
                for (IndicatorBreakdown indicatorBreakdown : list) {
                    if (!"0".equals(indicatorBreakdown.getCumulative())
                            && StringUtils.isNotBlank(indicatorBreakdown.getCumulative())) {
                        currentMonth = indicatorBreakdown.getCurrentMonth();
                        break;
                    }
                }
            }
            List<IndicatorRank> indicatorRanks = indicatorService.getRank3(code, currentMonth);
            for (IndicatorRank indicatorRank : indicatorRanks) {
                if ("永泰县".equals(indicatorRank.getArea())) {
                    //累计额、年度额
                    double cumulative = StringUtils.isBlank(indicatorRank.getCumulative()) ? 0 :
                            keepNumPostion(0, Double.parseDouble(indicatorRank.getCumulative())).intValue();
                    String datime = UtilsTools.formatDate(indicatorRank.getCurrentMonth());
                    if ("亿元".equals(unit)) {
                        cumulative = formatWan(cumulative, 4);
                        cumulative = keepNumPostion(2, cumulative);
                    }
                    ecolist.add(new CompEconDto(key, cumulative, cumulative, datime, unit));
                    break;
                }
            }
        }
        return ecolist;
    }


    //规上工业企业产值完成情况
    @ResponseBody
    @RequestMapping(value = "/queryCompEcon2", method = RequestMethod.GET)
    public Map<String, Object> queryCompEcon2() throws ParseException {
        IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime("A12");
        String currentMonth = indicator.getCurrentMonth();
        List<IndicatorRank> indicatorRanks = indicatorService.getRank3("A12", currentMonth);
        String unit = "亿元";
        for (IndicatorRank indicatorRank : indicatorRanks) {
            if ("永泰县".equals(indicatorRank.getArea())) {
                //累计额、年度额
                double cumulative = StringUtils.isBlank(indicatorRank.getCumulative()) ? 0 :
                        keepNumPostion(0, Double.parseDouble(indicatorRank.getCumulative())).intValue();
                String dateTime = UtilsTools.formatDate(indicatorRank.getCurrentMonth());
                if ("亿元".equals(unit)) {
                    cumulative = formatWan(cumulative, 4);
                    cumulative = keepNumPostion(2, cumulative);
                }

                Map<String, Object> map = new HashMap<>();
                map.put("growthRate", indicatorRank.getRatio());
                map.put("total", cumulative);
                map.put("name", indicatorRank.getIndustryName());
                map.put("dateTime", dateTime);
                return map;
            }
        }
        return null;
    }




    //规上工业企业产值完成情况
    @ResponseBody
    @RequestMapping(value = "/queryTYEconStatis", method = RequestMethod.GET)
    public List<TYEconStatisDto> queryTYEconStatis() throws ParseException {
        TreeMap<Integer, String> codeMap = new TreeMap() {
            {
                put(1, "A01"); //GDP
                put(2, "A02"); //一产
                put(3, "A03");//二产
                put(4, "A06");//三产
                put(5, "A11");//农业
                put(6, "A05");//工业
                put(7, "A07");//固投
                put(8, "A13");//社零
                put(9, "A04");//建筑业
                put(10, "A08");//工业固投
                put(11, "A09");//财政总收入
                put(12, "A10");//一般预算收入
                put(13, "A14");//进出口总值
                put(14, "A15");//实际利用外资
                put(15, "A18");//城镇收入
                put(16, "A19");//农村收入
            }
        };

        Set<Integer> keyset = codeMap.keySet();
        Iterator<Integer> iterator = keyset.iterator();
        List<TYEconStatisDto> ecolist = new ArrayList<>();

        while (iterator.hasNext()) {
            Integer key = iterator.next();
            String unit = "";
            String typeName = "";
            switch (key) {
                case 1:
                    typeName = "地区生产总值";
                    unit = "亿元";
                    break;
                case 2:
                    typeName = "第一产业增加值";
                    unit = "亿元";
                    break;
                case 3:
                    typeName = "第二产业增加值";
                    unit = "亿元";
                    break;
                case 4:
                    typeName = "第三产业增加值";
                    unit = "亿元";
                    break;
                case 5:
                    typeName = "农林牧渔业总产值";
                    unit = "亿元";
                    break;
                case 6:
                    typeName = "规模以上工业增加值";
                    unit = "亿元";
                    break;
                case 7:
                    typeName = "固定资产投资";
                    unit = "亿元";
                    break;
                case 8:
                    typeName = "社会消费品零售总额";
                    unit = "亿元";
                    break;
                case 9:
                    typeName = "建筑业增加值";
                    unit = "万元";
                    break;
                case 10:
                    typeName = "工业固投";
                    unit = "亿元";
                    break;
                case 11:
                    typeName = "一般公共预算总收入";
                    unit = "万元";
                    break;
                case 12:
                    typeName = "一般公共预算收入";
                    unit = "亿元";
                    break;
                case 13:
                    typeName = "进出口总值";
                    unit = "亿元";
                    break;
                case 14:
                    typeName = "实际利用外资";
                    unit = "亿元";
                    break;
                case 15:
                    typeName = "城镇居民人均可支配收入";
                    unit = "元";
                    break;
                case 16:
                    typeName = "农村居民人均可支配收入";
                    unit = "元";
                    break;
                default:
                    break;
            }

            String code = codeMap.get(key);
            IndicatorBreakdown indicator = indicatorService.getIndicatorDateTime(code);

            String currentMonth = indicator.getCurrentMonth();

            if ("A14".equals(code)) {
                if ("0".equals(indicator.getCumulative()) && "0".equals(indicator.getRatio())) {
                    //当月为0，则取上一个月的值
                    currentMonth = financeIncomeService.getSecondMonth(indicator.getCurrentMonth());
                } else {
                    currentMonth = indicator.getCurrentMonth();
                }
            }
            //固定资产投资取最新数据
            if ("A07".equals(code)) {
                List<IndicatorBreakdown> list = indicatorService.queryIndicatorBreakdowns("永泰县", "A07", null);
                for (IndicatorBreakdown indicatorBreakdown : list) {
                    if (!"0".equals(indicatorBreakdown.getCumulative())
                            && StringUtils.isNotBlank(indicatorBreakdown.getCumulative())) {
                        currentMonth = indicatorBreakdown.getCurrentMonth();
                        break;
                    }
                }
            }
            List<IndicatorRank> indicatorRanks = indicatorService.getRank3(code, currentMonth);
            for (IndicatorRank indicatorRank : indicatorRanks) {
                if ("永泰县".equals(indicatorRank.getArea())) {
                    //累计额、年度额
                    double cumulative = StringUtils.isBlank(indicatorRank.getCumulative()) ? 0 :
                            keepNumPostion(0, Double.parseDouble(indicatorRank.getCumulative())).intValue();
                    double ratio = StringUtils.isBlank(indicatorRank.getRatio()) ? 0 :
                            keepNumPostion(1, Double.parseDouble(indicatorRank.getRatio()));
                    String datime = UtilsTools.formatDate(indicatorRank.getCurrentMonth());
                    if ("亿元".equals(unit)) {
                        cumulative = formatWan(cumulative, 4);
                        cumulative = keepNumPostion(2, cumulative);
                    }
                        ecolist.add(new TYEconStatisDto(key, ratio, cumulative, datime, indicatorRank.getRank()+""));
                    break;
                }
            }
        }
        return ecolist;
    }
}
